#pragma once

//This transforms the mouses position to work even if the size of the window changes.
// Some trouble was encoutered with resizing the screen, so I modify the mouse position by
// the change in the screen size. It gets the base size then modifies the position if it ever
// differs. Otherwise bounding boxes do not line up to mouse clicks
class Cursor
{
private:
	POINT		m_Point;
	RECT		m_BaseRect;
	RECT		m_rClientRect;
	float		m_fxMod;
	float		m_fyMod;
	COORD		m_Pos;
	HWND		m_hWnd;
public:
	Cursor(){}
	~Cursor()
	{
		m_hWnd = NULL;
	}
	inline static Cursor* Engine()
	{
		static Cursor myCursor;
		return &myCursor;
	}
	inline bool Init(HWND hWnd,RECT ClientRect)
	{
		m_hWnd = hWnd;
		m_BaseRect = ClientRect;
		GetClientRect(m_hWnd,&m_rClientRect);
		m_fyMod = (float)m_rClientRect.bottom / (float)m_BaseRect.bottom;
		return true;
	}
	inline COORD Find()
	{
		GetClientRect(m_hWnd,&m_rClientRect);
		m_fxMod = (float)m_rClientRect.right / (float)m_BaseRect.right;
		m_fyMod = (float)m_rClientRect.bottom / (float)m_BaseRect.bottom;
		GetCursorPos(&m_Point);
		ScreenToClient(m_hWnd,&m_Point);
		m_Pos.X = (SHORT)(m_Point.x / m_fxMod);
		m_Pos.Y = (SHORT)(m_Point.y / m_fyMod);
		return m_Pos;
	}
};